// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import CM from "../../lib/cache/CM";
import MsgMgr from "../../lib/event/MsgMgr";
import Scene from "../../lib/scene/Scene";
import SceneMgr from "../../lib/scene/SceneMgr";
import UIMgr from "../../lib/ui/UIMgr";
import DBattle from "../cache/DBattle";
import DUser from "../cache/DUser";
import MsgEnum from "../common/MsgEnum";
import DBLevel from "../config/DBLevel";
import UIHall from "../ui/UIHall";
import UILevel from "../ui/UILevel";
import GameScene from "./GameScene";

const {ccclass, property} = cc._decorator;

@ccclass
export default class HallScene extends Scene {
    public type(): number {
        return 0;
    }

    public async onEnter(): Promise<void> {


        UIMgr.ins(UIMgr).show(UIHall);
        
        MsgMgr.on(MsgEnum.ON_ENTER_LEVEL, this.onEnterLevel, this);
    }

    public onExit(): void {
        MsgMgr.off(MsgEnum.ON_ENTER_LEVEL, this.onEnterLevel, this);
        UIMgr.ins(UIMgr).close(UIHall);
        UIMgr.ins(UIMgr).close(UILevel);
    }

    onEnterLevel(level){
        CM.ins(CM).get(DBattle).playId = DBLevel.getPlayId(level);
        CM.ins(CM).get(DBattle).level = level;
        SceneMgr.ins(SceneMgr).replaceScene(GameScene);
    }
}
